<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form" v-if="headerShow">
        <a-form size="mini" :model="pageData" layout="inline" :label-col-props="{ span: 9 }"
                :wrapper-col-props="{ span: 15 }" v-if="permissionStore.hasPermisson('xqdcx.cgxqd')">
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="调拨申请单号">
            <a-input @press-enter="huiche" class="bacClass" v-model="pageData.requestTransferCode"
                     :style="{ width: '300px' }"
                     allow-clear/>
          </a-form-item>
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="申请公司">
            <a-cascader v-model="pageData.firm" :options="pageData.applyFirmList" allow-clear ref="applyFirmRef"
                        @change="handleApplyFirmChange($event, pageData.firm)" class="bacClass"
                        :title="pageData.title"
                        :loading="pageData.firmChangeLoading" popup-container="html"/>
          </a-form-item>
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="原料名称">
            <a-input @press-enter="huiche" class="bacClass" v-model="pageData.rawMaterialName"
                     :style="{ width: '300px' }"
                     allow-clear/>
          </a-form-item>
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="纱批">
            <a-input @press-enter="huiche" class="bacClass" v-model="pageData.yarnBatch" :style="{ width: '300px' }"
                     allow-clear/>
          </a-form-item>
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="完成状态">
            <a-select popup-container="html" class="bacClass" v-model="pageData.finishState" allow-clear>
              <a-option :value="0">未完成</a-option>
              <a-option :value="1">已完成</a-option>
              <a-option :value="2">全部</a-option>
            </a-select>
          </a-form-item>
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="计划所需时间">
            <a-range-picker popup-container="html" :style="{ width: '300px' }" v-model="pageData.requestTransferTime"
                            class="bacClass"/>
          </a-form-item>
          <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="创建时间">
            <a-range-picker popup-container="html" :style="{ width: '300px' }" v-model="pageData.createTime"
                            class="bacClass"/>
          </a-form-item>
        </a-form>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18"/>
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18"/>
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <Toolbar :items="[
          `${permissionStore.hasPermisson('dbgl.cx') ? '查询' : ''}`,
          `${permissionStore.hasPermisson('dbgl.dbsq') ? '调拨申请' : ''}`,
          `${permissionStore.hasPermisson('dbgl.wc') ? '完成' : ''}`
        ]" @select="selectHandler" @alLocationApply="alLocationApply" @complete="complete">
        </Toolbar>
      </div>
    </template>

    <template #pageTabel>
      <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
        <div style="width: 100%; height: 100%">
          <encapsulation-agrid ref="table1Ref" :configaggrid="configTable1"></encapsulation-agrid>
        </div>
      </a-spin>
    </template>
    <!--选择调拨申请类型的框-->
    <a-modal v-model:visible="chooseApplyVisible" @ok="handleChooseApplyOk" @cancel="handleChooseApplyCancel"
             @close="handleChooseApplyCancel">
      <template #title>
        调拨申请类型选择
      </template>
      <div style="display: flex;justify-content: center;align-items: center">
        <a-radio-group v-model="pageData.applyType">
          <a-radio value="1">计划调拨申请</a-radio>
          <a-radio value="2">手工调拨申请</a-radio>
        </a-radio-group>
      </div>
    </a-modal>
    <!--计划调拨申请的框-->
    <a-drawer style="z-index: 999" ok-text="保存" cancel-text="关闭" :drawer-style="{ zIndex: 999 }" :width="400"
              popup-container=".arco-tabs-content" height="100%" placement="bottom" :visible="drawerData.isShowDrawer"
              unmountOnClose
              @cancel="drawerCancel"
    >
      <template #title>
        {{ drawerData.sideTitle }}
      </template>
      <div style="display:flex;justify-content: space-between;margin-bottom:40px;">
        <div class="search-box">
          <a-form size="mini" :model="drawerData" layout="inline" :label-col-props="{ span: 9 }"
                  :wrapper-col-props="{ span: 15 }">
            <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="生产截止时间">
              <a-range-picker
                  time-picker-props="YYYY-MM-DD"
                  popup-container="html" :style="{ width: '300px' }"
                  v-model="drawerData.productEndTime"
                  class="bacClass"
                  :disabled-date="disabledStartDate"/>
            </a-form-item>
          </a-form>
        </div>
        <div class="button-box">
          <el-button type="primary" @click="drawerSearch">查询</el-button>
          <el-button type="warning" @click="drawerAllocation">计划调拨</el-button>
        </div>
      </div>
      <div style="width: 100%; height: 90%">
        <encapsulation-agrid ref="table2Ref" :configaggrid="configTable2"
                             @update:listData="getTable2Data"></encapsulation-agrid>
      </div>
      <template #footer>
        <!--        只需要一个关闭弹窗的按钮-->
        <el-button @click="drawerCancel">关闭</el-button>
      </template>
    </a-drawer>
    <!--手工调拨的框、计划调拨的框-->
    <a-modal v-model:visible="allocationModal" :title="modalData.title" fullscreen
             :draggable="true" :bodyStyle="{ height: '100vh' }" @close="planAllocationModalCancel">
      <a-form ref="allocationFormRef" size="mini" :model="modalData" layout="inline" :label-col-props="{ span: 9 }"
              :wrapper-col-props="{ span: 15 }">
        <a-form-item>
          调拨申请单号：{{ modalData.requestTransferCode || '' }}
        </a-form-item>
        <a-form-item field="firm" :style="{ width: '300px' }" label-col-flex="90px" label="申请公司"
                     :rules="[{ required: true, message: '申请公司必填' }]">
          <a-cascader v-model="modalData.firm" :options="pageData.applyFirmList" allow-clear ref="applyFirmRef"
                      class="bacClass"
                      :title="modalData.title"
                      :loading="modalData.firmChangeLoading" popup-container="html" @change="handleFirmChange"
                      :key="modalData.firmChangeKey"/>
        </a-form-item>
        <a-form-item field="warehouseId" :style="{ width: '300px' }" label-col-flex="90px" label="仓库"
                     :rules="[{ required: true, message: '仓库必填' }]">
          <a-select popup-container="html" class="bacClass" v-model="modalData.warehouseId" allow-clear>
            <a-option v-for="item in modalData.warehouseList " :value="item.id">
              {{ item.warehouseName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item :style="{ width: '300px' }" field="requestTransferTime" label-col-flex="90px" label="所需时间"
                     :rules="[{ required: true, message: '所需时间必填' }]">
          <a-date-picker popup-container="html" :style="{ width: '300px' }" v-model="modalData.requestTransferTime"
                         class="bacClass" :default-value="modalData.today"/>
        </a-form-item>
        <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="备注">
          <a-input :style="{ width: '300px' }" v-model="modalData.remark" class="bacClass"/>
        </a-form-item>
      </a-form>
      <div style="margin-top: 15px" v-if="modalData.title=='手工调拨'">
        <el-button type="primary" size="small" @click="addLine">新增</el-button>
        <el-button type="danger" size="small" @click="delLine">删除</el-button>
      </div>
      <div style="width: 100%; height: 93%;margin-top:5px;" v-if="modalData.title=='手工调拨'">
        <encapsulation-agrid ref="table5Ref" :configaggrid="configTable5"></encapsulation-agrid>
      </div>
      <div style="width: 100%; height: 93%;margin-top:20px;" v-if="modalData.title=='计划调拨'">
        <encapsulation-agrid ref="table3Ref" :configaggrid="configTable3"></encapsulation-agrid>
      </div>
      <template #footer>
        <el-button @click="planAllocationModalCancel">关闭</el-button>
        <el-button type="primary" @click="planAllocationModalSave">保存</el-button>
      </template>
    </a-modal>
    <!--手工调拨新增的框-->
    <a-modal v-model:visible="isShowAddModal" fullscreen
             :draggable="true" :bodyStyle="{ height: '100vh' }" @close="addModalCancel">
      <div style="display:flex;justify-content: space-between;">
        <div>
          <a-form size="mini" :model="addModalData" layout="inline" :label-col-props="{ span: 9 }"
                  :wrapper-col-props="{ span: 15 }">
            <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="原料名称">
              <a-input class="bacClass" v-model="addModalData.rawMaterialName"
                       :style="{ width: '300px' }"
                       allow-clear/>
            </a-form-item>
            <a-form-item :style="{ width: '300px' }" label-col-flex="90px" label="纱批">
              <a-input class="bacClass" v-model="addModalData.batch"
                       :style="{ width: '300px' }"
                       allow-clear/>
            </a-form-item>
          </a-form>
        </div>
        <div
            style="width:200px;height: 40px;padding-bottom:30px;display:flex;justify-content: flex-end;padding-right: 25px;">
          <el-button @click=" addModalSearch
        " type="primary">查询
          </el-button>
        </div>
      </div>
      <div style="width: 100%; height: 95%">
        <encapsulation-agrid ref="table4Ref" :configaggrid="configTable4"></encapsulation-agrid>
      </div>
      <template #footer>
        <el-button type="primary" @click="addModalCancel">关闭</el-button>
        <el-button @click="addModalConfirm">确定</el-button>
      </template>
    </a-modal>
  </pageTabelLayout>
</template>

<script lang="ts" setup>
import dayjs from "dayjs";
import moment from 'moment';
import {post, get} from '@/api/http'
import {ref, reactive, onMounted, toRefs} from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import {cloneDeep} from 'lodash';
import {Form, Message, Modal} from '@arco-design/web-vue'
import usePermission from '@/store/modules/permission'
import tableColumns from './tableColumnConfig/table1'
import allocationTable from "@/views/AllocationManagement/AllocationManagement/tableColumnConfig/allocationTable";
import planAllocationModalTable
  from "@/views/AllocationManagement/AllocationManagement/tableColumnConfig/planAllocationModalTable";
import manualAllocationModalTable
  from "@/views/AllocationManagement/AllocationManagement/tableColumnConfig/manualAllocationModalTable";

onMounted(() => {
  getFirmData()
  getWareHouseData('')
  modalData.requestTransferTime = modalData.today
  doRefresh()
})
//设置权限
const permissionStore = usePermission()
const headerShow = ref<boolean>(true)
const modalVisible = ref<boolean>(false)
const chooseApplyVisible = ref<boolean>(false)
const isShowAddModal = ref<boolean>(false)
const applyFirmRef = ref<any>(null)
const allocationFormRef = ref<any>(null)
const disabledStartDate = (time: any) => {
  const currentTime = dayjs(time).format('YYYY-MM-DD')
  return currentTime < dayjs(drawerData.today).format('YYYY-MM-DD')
}
const handleChooseApplyOk = async () => {
  modalData.requestTransferTime = modalData.today
  if (pageData.applyType === '') {
    Message.error({
      content: '请选择调拨申请类型',
      duration: 5000,
    })
    return
  } else if (pageData.applyType === '1') {
    drawerData.productEndTime = [dayjs(new Date()).format('YYYY-MM-DD'), dayjs(new Date()).add(2, 'day').format('YYYY-MM-DD')]
    //计划调拨申请
    drawerData.isShowDrawer = true
  } else if (pageData.applyType === '2') {
    modalData.title = '手工调拨'
    await getRequestTransferCode()
    await getWareHouseData('')
    allocationModal.value = true
  }
}
const handleChooseApplyCancel = () => {
  pageData.applyType = '1'
}
const pageData = reactive<any>({
  pageLoading: false,
  firmChangeLoading: false,
  firm: '',
  applyFirmList: [],
  applyType: '1',
  sideTitle: '',
  requestTransferCode: '',//调拨申请单号
  rawMaterialName: '',
  yarnBatch: '',
  finishState: 0,
  requestTransferTime: '',
  createTime: '',
})
const drawerData = reactive<any>({
  isShowDrawer: false,
  sideTitle: '',
  productEndTime: [dayjs(new Date()).format('YYYY-MM-DD'), dayjs(new Date()).add(2, 'day').format('YYYY-MM-DD')],
})
const modalData = reactive<any>({
  firmChangeLoading: false,
  firmChangeKey: Date.now(),
  title: '',
  firm: '',//公司id
  requestTransferTime: null,
  remark: '',
  requestTransferCode: '',//调拨申请单号
  today: dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  warehouseId: '',//仓库id
  warehouseList: [],//仓库列表
  isFirst: 0,//是否第一次打开计划调拨或者手动调拨的弹窗 用于判断是否回显仓库默认数据
})
const drawerSearch = async () => {
  table2Ref.value.setQuery({
    productionStates: [0, 1, 3],
    dbStartTime: drawerData.productEndTime[0],
    dbEndTime: drawerData.productEndTime[1],
  })
}
const allocationModal = ref<boolean>(false)
//获取调拨申请单号
const getRequestTransferCode = async () => {
  const res = await post({
    url: 'wms/RequestTransfer/getAutomaticInfo',
  })
  try {
    if (res.code == 200) {
      modalData.requestTransferCode = res.data.code
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  } catch (e) {
    console.log(e)
  }
}
let table2Data: any;
const getTable2Data = (data: any) => {
  table2Data = data
}
//获取点击计划调拨里面的表格数据
const getPlanAllocationTableData = async (data: any) => {
  const res = await post({
    url: 'wms/RequestTransfer/getRaw',
    data,
  })
  try {
    if (res.code == 200) {
      table3Ref.value.setdataListIterface(res.data)
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  } catch (e) {
    console.log(e)
  }
}
//获取手工调拨表格数据
const getManualAllocationTableData = async (data: any) => {
  const res = await post({
    url: 'wms/RequestTransfer/getWmsRawInfo',
    data
  })
  try {
    if (res.code == 200) {
      const renderData = res.data.map((item: any) => {
        return {
          ...item,
          requestTransferWeight: 0,

        }
      })
      table4Ref.value.setdataListIterface(renderData)
    }
  } catch (e) {
    console.log(e)
  }
}
const addModalSearch = () => {
  getManualAllocationTableData({
    rawMaterialName: addModalData.rawMaterialName,
    batch: addModalData.batch,
    warehouseId: modalData.warehouseId,
  })
}
//点击计划调拨
const drawerAllocation = async () => {
  modalData.title = '计划调拨'
  await getRequestTransferCode()
  await getPlanAllocationTableData(table2Data)
  modalData.isFirst = 0
  await getWareHouseData('')
  allocationModal.value = true
}
const table1Ref = ref<any>(null)
let configTable1 = {
  url: 'wms/RequestTransfer/getPage', //接口路径
  queryData: {
    requestTransferCode: pageData.requestTransferCode,
    firm: pageData.firm,
    rawMaterialName: pageData.rawMaterialName,
    yarnBatch: pageData.yarnBatch,
    requestTransferTime: pageData.requestTransferTime,
    finishState: pageData.finishState,
    createTime: pageData.createTime
  },
  paginationShow: true, //分页是否显示
  invokeiIterface: false, //是否调用接
  rowMultiSelectWithClick: true, //点击行是否多选
  column: tableColumns,
  fileName: 'AllocationManagement-1',
}
const table2Ref = ref<any>(null)
let configTable2 = {
  url: 'planSingle/planMachineTask/getPageInfo', //接口路径
  queryData: {
    productionStates: [0, 1, 3],
    dbStartTime: Array.isArray(drawerData.productEndTime) ? drawerData.productEndTime[0] : '',
    dbEndTime: Array.isArray(drawerData.productEndTime) ? drawerData.productEndTime[1] : '',
    dbcustomName: '1'
  },
  paginationShow: true, //分页是否显示
  invokeiIterface: true, //是否调用接
  rowMultiSelectWithClick: true, //点击行是否多选
  column: allocationTable,
  fileName: 'AllocationManagement-2',
}
const table3Ref = ref<any>(null)
let configTable3 = {
  url: '', //接口路径
  queryData: {},
  paginationShow: false, //分页是否显示
  invokeiIterface: false, //是否调用接
  rowMultiSelectWithClick: true, //点击行是否多选
  column: planAllocationModalTable,
  fileName: 'AllocationManagement-3',
}
const table4Ref = ref<any>(null)
let configTable4 = {
  url: '', //接口路径
  queryData: {},
  paginationShow: false, //分页是否显示
  invokeiIterface: false, //是否调用接
  rowMultiSelectWithClick: true, //点击行是否多选
  column: planAllocationModalTable,
  isRowClickSelect:true,
  fileName: 'AllocationManagement-4',
}
const table5Ref = ref<any>(null)
let configTable5 = {
  url: '', //接口路径
  queryData: {},
  paginationShow: false, //分页是否显示
  invokeiIterface: false, //是否调用接
  rowMultiSelectWithClick: true, //点击行是否多选
  column: manualAllocationModalTable,
  fileName: 'AllocationManagement-5',
}
const findInnerFirm: any = (node: any) => {
  if (!node.children) {
    return node.value
  }
  if (node.children.length === 1) {
    return findInnerFirm(node.children[0])
  }
  return null
}
//获取公司下拉信息
const getFirmData = () => {
  get({
    url: '/admin/acl/user/getMemberIdByJwtToken',
  }).then((res) => {
    post({
      url: 'admin/acl/user/findUserToken',
      data: {
        name: res,
      },
    }).then((res: any) => {
      if (res.code === 200) {
        post({
          url: 'org/baCompany/getTreeCompanyByUser',
          data: {},
        }).then(({code, data}) => {
          if (code === 200) {
            pageData.applyFirmList = data
            if (data.length === 1) {
              const firm = findInnerFirm(data[0])
              pageData.firm = firm
              modalData.firm = firm
            } else {
              pageData.firm = ''
              modalData.firm = ''
            }
          }
        })
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
  })
}
//获取仓库下拉信息
const getWareHouseData = async (id: any) => {
  const res = await post({
    url: 'wms/warehouse/getWarehouseByPara',
    data: {
      firmId: id == '' ? '' : id,
      virtuallyState: 0,
      warehouseTypeName: '原纱仓'
    }
  })
  try {
    if (res.code == 200) {
      if (res.data.length > 0) {
        modalData.warehouseId = res.data[0].id
      }
      modalData.warehouseList = res.data
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  } catch (e) {
    console.log(e)
  }
}
const handleFirmChange = (e: any) => {
  modalData.isFirst = modalData.isFirst + 1
  if (modalData.isFirst > 1 && !e) {
    modalData.warehouseId = ''
    return
  }
  getWareHouseData(e)
}
const doRefresh = () => {
  table1Ref.value.setQuery({
    requestTransferCode: pageData.requestTransferCode,
    firmId: pageData.firm,
    rawMaterialName: pageData.rawMaterialName,
    yarnBatch: pageData.yarnBatch,
    finishState: pageData.finishState == 2 ? '' : pageData.finishState,
    startTime: Array.isArray(pageData.requestTransferTime) ? pageData.requestTransferTime[0] : '',//所需开始日期
    endTime: Array.isArray(pageData.requestTransferTime) ? pageData.requestTransferTime[1] : '',//所需结束日期
    startTimeB: Array.isArray(pageData.createTime) ? pageData.createTime[0] : '',//创建开始日期
    endTimeB: Array.isArray(pageData.createTime) ? pageData.createTime[1] : '',//创建结束日期
  })
}
const selectHandler = () => {
  doRefresh()
}
const huiche = () => {
  selectHandler()
}
const drawerCancel = () => {
  for (let key in drawerData) {
    if (key === 'isShowDrawer') {
      drawerData[key] = false
    } else if (key === 'productEndTime') {
      drawerData[key] = []
    } else {
      drawerData[key] = ''
    }
  }
}
const handleApplyFirmChange = (e: any, v: any) => {
}
const alLocationApply = () => {
  chooseApplyVisible.value = true
  drawerData.sideTitle = '计划调拨申请'
}
const planAllocationModalSave = async () => {
  const valid = await allocationFormRef.value.validate()
  if (modalData.title === '手工调拨') {
    if (!valid) {
      //这里拿到的公司是包含所有层级的 处理一下只要尾级用于传参
      const splitArr = applyFirmRef.value.selectViewValue[0].label.split('/')
      const firm = splitArr[splitArr.length - 1].trim()
      const warehouseName = modalData.warehouseList.filter((item: any) => {
        return item.id === modalData.warehouseId
      })[0].warehouseName
      const params = table5Ref.value.getListData().map((item: any) => {
        if (item.requestTransferNum !== 0 && item.requestTransferNum !== undefined && item.requestTransferNum !== null && item.requestTransferWeight !== 0) {
          return {
            ...item,
            requestTransferCode: modalData.requestTransferCode,
            requestTransferTime: modalData.requestTransferTime,
            firmId: modalData.firm,
            firm,
            warehouseId: modalData.warehouseId,
            warehouseName,
            remark: modalData.remark,
          }
        } else {
          return null
        }
      }).filter((item2: any) => item2 !== null);
      if (params.length === 0) {
        Message.error({
          content: '当前勾选所有行数据调拨申请件数或调拨申请数量为0，请重新填写',
          duration: 5000,
        })
        return
      }
      const res = await post({
        url: 'wms/RequestTransfer/insert',
        data: params
      })
      try {
        if (res.code == 200) {
          Message.success({
            content: res.message,
            duration: 5000,
          })
          planAllocationModalCancel()
          doRefresh()
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          })
        }
      } catch (e) {
        console.log(e)
      }
    }
  } else if (modalData.title === '计划调拨') {
    if (!valid) {
      //这里拿到的公司是包含所有层级的 处理一下只要尾级用于传参
      const splitArr = applyFirmRef.value.selectViewValue[0].label.split('/')
      const firm = splitArr[splitArr.length - 1].trim()
      const warehouseName = modalData.warehouseList.filter((item: any) => {
        return item.id === modalData.warehouseId
      })[0].warehouseName
      const params = table3Ref.value.getListData().map((item: any) => {
        if (item.requestTransferNum > 0 && item.requestTransferWeight > 0) {
          return {
            ...item,
            requestTransferCode: modalData.requestTransferCode,
            requestTransferTime: modalData.requestTransferTime,
            firmId: modalData.firm,
            firm,
            warehouseId: modalData.warehouseId,
            warehouseName,
            remark: modalData.remark,
          }
        } else {
          return null
        }
      }).filter((item2: any) => item2 !== null);
      if (params.length === 0) {
        Message.error({
          content: '当前所有行数据调拨申请件数或调拨申请数量为0，请重新填写',
          duration: 5000,
        })
        return
      }
      const res = await post({
        url: 'wms/RequestTransfer/insert',
        data: params
      })
      try {
        if (res.code == 200) {
          Message.success({
            content: res.message,
            duration: 5000,
          })
          planAllocationModalCancel()
          drawerCancel()
          doRefresh()
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          })
        }
      } catch (e) {
        console.log(e)
      }
    }
  }

}
const planAllocationModalCancel = () => {
  allocationModal.value = false
  for (let key in modalData) {
    if (key === 'firmChangeLoading') {
      modalData[key] = false
    } else if (key === 'firmChangeKey') {
      modalData.firmChangeKey = Date.now()
    } else if (key === 'today') {
      modalData.today = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
    } else if (key === 'isFirst') {
      modalData[key] = 0
    } else {
      modalData[key] = ''
    }
    allocationFormRef.value.resetFields()
  }
}
//点击完成按钮
const complete = () => {
  if (table1Ref.value.getSelectedRows().length === 0) {
    Message.error({
      content: '请选择一条数据',
      duration: 5000,
    })
    return
  }
  if (table1Ref.value.getSelectedRows().some((item: any) => item.finishState == 1)) {
    Message.error({
      content: '当前勾选的数据中存在已完成的数据，请重新选择',
      duration: 5000,
    })
    return
  } else {
    Modal.confirm({
      title: '提示',
      content: '是否确认完成？',
      onOk: async () => {
        const params = table1Ref.value.getSelectedRows().map((item: any) => {
          return {
            id: item.id,
            finishState: 1
          }
        })
        const res = await post({
          url: 'wms/RequestTransfer/update',
          data: params,
        })
        try {
          if (res.code == 200) {
            Message.success({
              content: res.message,
              duration: 5000,
            })
            doRefresh()
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            })
          }
        } catch (e) {
          console.log(e)
        }
      },
    })
  }
}
const addLine = async () => {
  await getManualAllocationTableData({
    rawmaterialName: addModalData.rawMaterialName,
    batch: addModalData.batch,
    warehouseId: modalData.warehouseId,
  })
  isShowAddModal.value = true
}
const delLine = () => {
  if (table5Ref.value.getSelectedRows().length === 0) {
    Message.error({
      content: '请至少选择一条数据进行删除',
      duration: 5000,
    })
    return
  }
  const ids = table5Ref.value.getSelectedRows().map((item: any) => {
    return item.rawmaterialCode
  })
  const currentRows = table5Ref.value.getListData().filter((item: any) => {
    return ids.indexOf(item.rawmaterialCode) === -1
  })
  table5Ref.value.setdataListIterface(currentRows)
}
const addModalData = reactive<any>({
  rawMaterialName: '',
  batch: '',
})
const addModalCancel = () => {
  isShowAddModal.value = false
  for (let key in addModalData) {
    addModalData[key] = ''
  }
}
const addModalConfirm = () => {
  //table5的全部数据
  const table5Data = table5Ref.value.getListData()
  //table4的勾选数据
  const table4SelectedRows = table4Ref.value.getSelectedRows().map((item: any) => {
    return {
      ...item,
      requestTransferWeight: item.requestTransferWeight ? item.requestTransferWeight : 0,
      requestTransferNum: item.requestTransferNum ? item.requestTransferNum : 0,
    }
  })
  if(table4SelectedRows.length === 0){
    Message.error({
      content: '请至少选择一条数据进行添加',
      duration: 5000,
    })
    return
  }
  const newData = []
  const clonet5Data = cloneDeep(table5Data)
  let clonet4SelectedRows = cloneDeep(table4SelectedRows)
  if (clonet5Data.length === 0) {
    table5Ref.value.setdataListIterface(clonet4SelectedRows)
  } else {
    table4SelectedRows.forEach((table4Row) => {
      for (let index = 0; index < clonet5Data.length; index++) {
        if (('' +
                table4Row.customName +
                table4Row.rawmaterialCode +
                table4Row.rawmaterialName +
                table4Row.yarnCard +
                table4Row.batch +
                table4Row.colorCode +
                table4Row.colorName +
                table4Row.level +
                table4Row.pieceWeight)
            === ('' +
                clonet5Data[index].customName +
                clonet5Data[index].rawmaterialCode +
                clonet5Data[index].rawmaterialName +
                clonet5Data[index].yarnCard +
                clonet5Data[index].batch +
                clonet5Data[index].colorCode +
                clonet5Data[index].colorName +
                clonet5Data[index].level +
                clonet5Data[index].pieceWeight)) {
          clonet5Data[index]['requestTransferNum'] = Number(table4Row['requestTransferNum']) + Number(clonet5Data[index]['requestTransferNum'])
          break;
        } else {
          if (index === clonet5Data.length - 1) {
            newData.push(table4Row)
          }
        }
      }
    })
    table5Ref.value.setdataListIterface([...clonet5Data, ...newData])
  }
  isShowAddModal.value = false
  for (let key in addModalData) {
    addModalData[key] = ''
  }
}
</script>
<style scoped lang="less">
:deep(.arco-table-td-content) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

:deep(.arco-picker input) {
  padding-left: 0 !important;
}

:deep(.arco-picker) {
  padding-left: 0 !important;
}

:deep(.arco-picker-separator) {
  padding: 0 !important;
}
</style>